package com.whu.helpluojia.controller;

import com.whu.helpluojia.common.BaseContext;
import com.whu.helpluojia.domain.Comment;
import com.whu.helpluojia.domain.dto.CommentDto;
import com.whu.helpluojia.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @PostMapping
    public void add(@RequestBody Comment comment){

        Long userId=BaseContext.getCurrentId();

        commentService.addComment(userId,comment);
    }

    @GetMapping("/{id}")
    public List<CommentDto> getCommentByConsultId(@PathVariable Long id){

        List<CommentDto>commentDtos=new ArrayList<>();

        commentDtos=commentService.getCommentByConsultId(id);

        return commentDtos;
    }
}
